package com.ccbooks.listener;

import com.ccbooks.bo.BookMarkBo;
import com.ccbooks.bo.FileBo;
import com.ccbooks.util.BooksEngine;
import com.ccbooks.util.PDB.BooksEnginePDB;
import com.ccbooks.view.BookContentView;
import com.ccbooks.view.R;

import android.view.View;
import android.view.View.OnClickListener;

public class BtnBookMarkOnClickListener implements OnClickListener {

	private BookContentView bcv;
	private BookMarkBo bmo;
	
	public BtnBookMarkOnClickListener(BookContentView bcv) {
		super();
		this.bcv = bcv;
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(bmo == null)	{
			bmo = new BookMarkBo(bcv);
		}
		if (bcv.mark == null) {
			//isMark = b;
			bcv.btnBookMark.setBackgroundDrawable(bcv
					.getResources().getDrawable(
							R.drawable.content_btn_onmark));

				if(FileBo.BOOKTYPE_TXT.equals(bcv.book.booktype)){
						bmo.addMarksByDb(bcv.book.id, BooksEngine.markPoint,
								BooksEngine.content.substring(0, 20));
				}else if(FileBo.BOOKTYPE_PDB.equals(bcv.book.booktype)){		
						bmo.addMarksByDb(bcv.book.id, BooksEnginePDB.markPoint,
								BooksEnginePDB.content.substring(0, 20));
				}else if(FileBo.BOOKTYPE_CHM.equals(bcv.book.booktype)){
					
				}else if(FileBo.BOOKTYPE_HTML.equals(bcv.book.booktype)){
					
				}else if(FileBo.BOOKTYPE_PDF.equals(bcv.book.booktype)){
				
				}
			
			BookMarkBo.isMark(bcv);

		}else {
			bcv.btnBookMark.setBackgroundDrawable(bcv
					.getResources().getDrawable(
							R.drawable.content_btn_outmark));
			bmo.delMarkByDb(bcv.book.id, bcv.mark.id);
			bcv.mark = null;
			BookMarkBo.isMark(bcv);
		}
		
	}
	
}
